{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "850a3802-29bf-4bfa-bf04-ed76979a45c5",
   "metadata": {},
   "outputs": [],
   "source": [
    "#1.程序开始-欢迎提示，内容简洁明了，说明程序的功能\n",
    "#询问用户是否需要启动程序，输入需要或不需要，指定输入y/n（大小写均可），可以用strip函数，如输入y/n以外的值则显示“输入值非法！请输入y/n”\n",
    "#   如用户输入n：\n",
    "#   结束程序\n",
    "#   如何用户输入非法：\n",
    "#   提示输入非法，并重新询问是否启动启动程序\n",
    "#   如用户输入y：\n",
    "#2.    显示进入主循环（while true循环）\n",
    "#        -显示功能菜单（提示输入1 为添加联系人；输入2 为删除联系人；输入3 为查看单个联系人；输入4 为查看整个通讯录；输入5 为退出程序）\n",
    "#        -显示输入操作的编号\n",
    "#\n",
    "#        -如果输入的是1（添加联系人）：\n",
    "#           -提示输入姓名\n",
    "#           -如果输入的姓名为空：\n",
    "#               -显示错误并重新进入上级功能选择界面\n",
    "#           -如果输入的姓名已存在，提示已存在用户信息，并询问是否更新已存在人员的信息y/n，大小写均可，用 strip 函数\n",
    "#               -如果用户输入n：\n",
    "#                  -提示请输入新的姓名\n",
    "#               -如果用户名输入不合法：\n",
    "#                  -提示错误并返回是否更新已存在人员信息的询问\n",
    "#               -如果用户输入y：\n",
    "#                  -退出这个判断并进入主循环中输入正常姓名后的数据录入界面\n",
    "#            -如果输入的不为空值且不重复：\n",
    "#               -提示输入备注名（可以为空）\n",
    "#               -提示输入邮箱（不可为空）\n",
    "#               -提示输入手机号码1（不可为空）\n",
    "#               -提示输入手机号码2（可以为空）\n",
    "#               -以上信息都录入完成后，构造小字典并作为value存入通讯录大字典，key为录入的姓名\n",
    "#               -提示“录入成功”\n",
    "#\n",
    "#         —如果输入的是2（删除联系人）：\n",
    "#            -如果通讯录本身为空：\n",
    "#               -提示“通讯录中没有任何联系人”，并回到主循环\n",
    "#            -如果通讯录不为空：\n",
    "#               -提示“请输入要删除的人员姓名”\n",
    "#               -如果姓名在通讯录中：\n",
    "#                  -删除大字典中的联系人\n",
    "#                  -提示“删除成功”\n",
    "#               -如果姓名为空或不存在：\n",
    "#                  -提示“输入不合法或找不到联系人”并退出这一层判断\n",
    "#               -提示“要删除的人员姓名”\n",
    "#\n",
    "#         -如果录入的是3（查看单个联系人）：\n",
    "#            -如果通讯录本身为空：\n",
    "#               -提示“通讯录中没有任何联系人”，并回到主循环\n",
    "#            -如果通讯录不为空：\n",
    "#               -提示“请输入要查阅的人员姓名”\n",
    "#               -如果姓名在通讯录中：\n",
    "#                  -提示“请查阅如下个人信息”\n",
    "#                  -根据录入的姓名打印大字典对应的key和value\n",
    "#               -如果姓名为空或不存在：\n",
    "#                  -提示“输入不合法或找不到联系人”并退出这一层判断\n",
    "#               -提示“请输入要查阅的人员姓名”\n",
    "#\n",
    "#         -如果录入的是4（查看整个通讯录）：\n",
    "#            -如果通讯录本身为空：\n",
    "#               -提示“通讯录中没有任何联系人”，并回到主循环\n",
    "#            -否则：\n",
    "#               -提示“请查阅通讯录”\n",
    "#               -按行打印通讯录大字典信息\n",
    "#\n",
    "#         -如果录入的是5（退出程序）\n",
    "#            -提示“再见”，结束循环\n",
    "#\n",
    "#         -否则：\n",
    "#            -提示“无效输入，请输入 1-5 的数字”"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4153392b-3843-4afb-8cc5-faedcd273fdf",
   "metadata": {},
   "outputs": [],
   "source": [
    "contacts={}\n",
    "print('欢迎使用通讯录功能')\n",
    "pgm_start=input('请选择是否启动程序?请输入y(是)或n(不是)，不区分大小写: ').strip().lower()\n",
    "if pgm_start=='n':\n",
    "    print('再见!')\n",
    "elif pgm_start not in ('n','y'):\n",
    "    print('输入非法!')\n",
    "else:\n",
    "    while True:\n",
    "        print('\\n请选择操作菜单: ')\n",
    "        print('1.添加联系人')\n",
    "        print('2.删除联系人')\n",
    "        print('3.查阅单个人员联系信息')\n",
    "        print('4.查阅所有人员联系信息')\n",
    "        print('5.退出程序')\n",
    "        choice=input('请选择你需要的功能: ').strip()\n",
    "        if choice=='1':\n",
    "            name=input('请输入要添加的人员姓名: ')\n",
    "            if name=='':\n",
    "                print('非法输入!')\n",
    "            elif name in contacts:\n",
    "                renew=input('人员已存在!是否更新人员信息? y是/n否(不区分大小写): ').strip().lower()\n",
    "                if renew=='n':\n",
    "                    print('请重新输入人员姓名')\n",
    "                elif renew=='':\n",
    "                    print('非法输入!')\n",
    "                else:\n",
    "                    remark=input('请输入备注名(没有可不填): ')\n",
    "                    email=input('请输入邮箱(必填): ')\n",
    "                    phone1=input('请输入第一个手机号(必填): ')\n",
    "                    phone2=input('请输入第二个手机号(没有可不填): ')\n",
    "                    contact_info={\n",
    "                        '备注名':remark if remark !='' else None,\n",
    "                        '邮箱':email,\n",
    "                        '手机号1':phone1,\n",
    "                        '手机号2':phone2 if phone2 !='' else None\n",
    "                    }\n",
    "                    contacts[name]=contact_info\n",
    "                    print('人员信息更改成功!')\n",
    "                    \n",
    "            else:\n",
    "                remark=input('请输入备注名(没有可不填): ')\n",
    "                email=input('请输入邮箱(必填): ')\n",
    "                phone1=input('请输入第一个手机号(必填): ')\n",
    "                phone2=input('请输入第二个手机号(没有可不填): ')\n",
    "                contact_info={\n",
    "                    '备注名':remark if remark !='' else None,\n",
    "                    '邮箱':email,\n",
    "                    '手机号1':phone1,\n",
    "                    '手机号2':phone2 if phone2 !='' else None\n",
    "                }\n",
    "                contacts[name]=contact_info\n",
    "                print('添加成功!')             \n",
    "                \n",
    "        elif choice=='2':\n",
    "            if len(contacts)==0:\n",
    "                print('通讯录中为空,无可删除的联系人!')\n",
    "            else:\n",
    "                del_name=input('请输入要删除的人员姓名: ')\n",
    "                if del_name in contacts:\n",
    "                    del contacts[del_name]\n",
    "                    print('删除成功!')\n",
    "                else:\n",
    "                    print('输入不合法或找不到联系人!')\n",
    "\n",
    "        elif choice=='3':\n",
    "            if len(contacts)==0:\n",
    "                print('通讯录中为空,无可查阅的联系人!')\n",
    "            else:\n",
    "                find_name=input('请输入要查询的人员姓名: ')\n",
    "                if find_name in contacts:\n",
    "                    print(f'你查询的人员信息为:{contacts[find_name]}')\n",
    "                else:\n",
    "                    print('输入不合法或找不到联系人!')\n",
    "\n",
    "        elif choice=='4':\n",
    "            if len(contacts)==0:\n",
    "                print('通讯录中为空,无可查阅的联系人!') \n",
    "            else:\n",
    "                for name in contacts:\n",
    "                    info=contacts[name]\n",
    "                    print('\\n姓名:',name)\n",
    "                    print('备注名:',info['备注名'] if info['备注名'] else '无')\n",
    "                    print('邮箱:',info['邮箱'])\n",
    "                    print('手机号1:',info['手机号1'])\n",
    "                    print('手机号2:',info['手机号2'] if info['手机号2'] else '无')\n",
    "\n",
    "        elif choice=='5':\n",
    "            print('欢迎再次使用!')\n",
    "            break\n",
    "\n",
    "        else:\n",
    "            print('非法输入!')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
